<?php
namespace App\Modules\Relationship\Models;


use App\Http\Services\CommonServices;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use App\Http\Model\Base;

class RelationshipLevelNoticeModel extends Base {

    protected $table = "rs_relationship_level_notice";
    protected $fields = ['id', 'rs_code as rsCode', 'user_id as userId',
        'is_notice as isNotice', 'level'];

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
        $this->tablePrefix = env('DB_PREFIX');
    }

    public function creatRecord ($rsCode, $userId, $level) {
        $data = array(
            'rs_code'=>$rsCode,
            'user_id'=>$userId,
            'is_notice'=>1,
            'level'=>$level
        );
        $re = DB::table($this->table)->insert($data);
        return $re;
    }

    public function deleteRecord ($rsCode, $userId) {
        $data = array(
            'rs_code'=>$rsCode,
            'user_id'=>$userId
        );
        $re = DB::table($this->table)->where($data)->update(['is_notice'=>0, 'is_deleted'=> 1]);
        return $re;
    }

    public function getRecord ($rsCode, $userId) {
        $data = array(
            'rs_code'=>$rsCode,
            'user_id'=>$userId,
            'is_deleted'=> 0,
            'is_notice'=>1
        );
        $re = $this->getOneByCondition($data, $this->fields);
        return $re;
    }
    
}

